<?php
	$filterUrls = array(
		__('Title')=> array('sort'=>'Event.title','direction'=>'asc'),
		__('Most recent')=> array('sort'=>'Event.created','direction'=>'desc'),
		__("Popular") => array('sort'=>'(Event.soundscool_count+Event.whosin_count)','direction'=>'desc'),
		__('Free')=> array('sort'=>'Event.event_cost','direction'=>'asc'),
		__('Most viewed')=> array('sort'=>'Event.view_count','direction'=>'desc'),
	);
	foreach($filterUrls as &$filterUrl)
	{
		$filterUrl = am(am($this->params['named'],$this->params['pass']),$filterUrl);
		$filterUrl['page'] = null;
		$filterUrl = $appHtml->url($filterUrl);
	}
	$pagingUrl = $this->getPagingUrl();
	$presentUrl = $appHtml->url(am($pagingUrl,array_diff_key($this->params['named'],array("page"=>null))));
	if(!isset($this->params['named']['sort']))
	{
		$presentUrl = $html->url($filterUrls[__('Title')]);
	}else if($this->params['isAjax']=='')
	{
		$presentUrl = $appHtml->url($presentUrl.'/sort:Event.created/direction:desc');
	}	
	$filterUrls = array_flip($filterUrls);	
	$paginator->options(array('url'=>$this->getPagingUrl()));
?>
<div class="index_filter">
<?php 
	//echo $form->input('event_sort_filter',array('label'=>__('Sort By'),'type'=>'select','options'=>$filterUrls,'onchange'=>"$('#sortLink').attr('href',$(this).val()).trigger('click')",'value'=>$presentUrl));
	echo $form->input('event_sort_filter',array('label'=>__('Sort By'),'type'=>'select','options'=>$filterUrls,'onchange'=>"alert($(this).val());",'value'=>$presentUrl));
?>

<a style = 'display: none;' id="sortLink" class="paging_ajaxify"></a>
</div>
<div class="clear"></div>